package com.example.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.po.Medicalrecord;
import com.example.service.MedicalrecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/medicalrecord")
public class MedicalRecordController {
    @Autowired
    private MedicalrecordService medicalrecordService;

    @RequestMapping("/getbyregisterid")
    public Medicalrecord getById(Integer registerid) {
        System.out.println("getbyregisterid   registerid="+registerid );
        QueryWrapper<Medicalrecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("RegistID",registerid);
        List<Medicalrecord> list=medicalrecordService.list(queryWrapper);
        if (list == null || list.size() == 0){
            return null;
        }else{
            return list.get(0);
        }
    }

    @RequestMapping("/saveOrUpdate")
    public Boolean saveOrUpdate(@RequestBody Medicalrecord medicalrecord) {
        return medicalrecordService.saveOrUpdate(medicalrecord);
    }

    @RequestMapping("/over")
    public Boolean over(@RequestParam Integer registid,
                        @RequestParam String  result) {
        QueryWrapper<Medicalrecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("RegistID",registid);
        Medicalrecord medicalrecord = new Medicalrecord();
        medicalrecord=medicalrecordService.getOne(queryWrapper);
        medicalrecord.setCasestate(3);
        medicalrecord.setDiagnosis(result);
        return medicalrecordService.updateById(medicalrecord);
    }
}
